/**
 * Copyright (c) 2004-2015 All Rights Reserved.
 */
package com.zbest.zpay.web.controller.activity;

import org.springframework.stereotype.Controller;

import com.zbest.zpay.web.controller.BaseController;

/**
 * 
 *
 * @author czhou3306@gmail.com
 * @version $Id: FileUploadController.java, v0.1 2015年12月9日 下午6:29:28 czhou3306@gmail.com Exp $
 */
@Controller
public class MaterialController extends BaseController {/*

    *//**
     * 上传素材
     * 
     * @param request
     * @param response
     * @return
     *//*
    @RequestMapping(value = "/material/upload", method = RequestMethod.POST)
    @ResponseBody
    public String uploadMaterial(HttpServletRequest request, HttpServletResponse response) {

        Merchant merchant = (Merchant) request.getSession().getAttribute(ContextField.KEY_MERCHANT);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put(ContextField.KEY_MERCHANT_ID, merchant.getMerchantId());

        //创建一个通用的多部分解析器  
        CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver(request
            .getSession().getServletContext());
        //判断 request 是否有文件上传,即多部分请求  
        if (multipartResolver.isMultipart(request)) {
            //转换成多部分request    
            MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest) request;
            //取得request中的所有文件名  
            Iterator<String> iter = multiRequest.getFileNames();
            List<MultipartFile> fileList = new ArrayList<MultipartFile>();
            while (iter.hasNext()) {
                //取得上传文件  
                MultipartFile file = multiRequest.getFile(iter.next());
                fileList.add(file);
            }
            map.put(ContextField.KEY_FILE_LIST, fileList);
        }

        ProcessResult result = processService.execute(ProcessConstant.PROCESS_UPLOAD_MATERIAL, map);
        if (result.isSuccess()) {
            return newSuccessResult(result.getResultObject());
        } else {
            return newErrorResult(result.getCode());
        }

    }

    *//**
     * 上传图文
     *
     * @param request
     * @param response
     * @return
     *//*
    @RequestMapping(value = "/material/saveNewsMaterial", method = RequestMethod.GET)
    @ResponseBody
    public String saveMaterial(HttpServletRequest request, @RequestParam String newsList) {
        Merchant merchant = (Merchant) request.getSession().getAttribute(ContextField.KEY_MERCHANT);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put(ContextField.KEY_MERCHANT_ID, merchant.getMerchantId());
        map.put(ContextField.KEY_NEWS_LIST,
            newsList.replaceAll(" ", "").replaceAll("[\\t\\n\\r]", ""));

        ProcessResult result = processService.execute(ProcessConstant.PROCESS_SAVE_NEWS_MATERIAL,
            map);
        if (result.isSuccess()) {
            return newSuccessResult(result.getResultObject());
        } else {
            return newErrorResult(result.getCode());
        }
    }

    *//**
     * 查询用户的素材
     * 
     * @param request
     * @param response
     * @return
     *//*
    @RequestMapping(value = "/material/query", method = RequestMethod.GET)
    @ResponseBody
    public String queryMaterial(HttpServletRequest request, @RequestParam String type,
                                @RequestParam String pageNo, @RequestParam String pageSize) {

        Merchant merchant = (Merchant) request.getSession().getAttribute(ContextField.KEY_MERCHANT);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put(ContextField.KEY_MERCHANT_ID, merchant.getMerchantId());
        map.put(ContextField.KEY_MATERIAL_TYPE, type);
        map.put(ContextField.KEY_PAGE_NO, pageNo);
        map.put(ContextField.KEY_PAGE_SIZE, pageSize);

        ProcessResult result = processService.execute(ProcessConstant.PROCESS_QUERY_MATERIAL, map);
        if (result.isSuccess()) {

            return newSuccessResult(result.getResultObject());
        } else {
            return newErrorResult(result.getCode());
        }

    }

    *//**
     * 查询用户的素材
     * 
     * @param request
     * @param response
     * @return
     *//*
    @RequestMapping(value = "/material/querylibrary", method = RequestMethod.GET)
    @ResponseBody
    public String queryLibrary(HttpServletRequest request, @RequestParam String type,
                               @RequestParam String pageNo, @RequestParam String pageSize) {

        Map<String, Object> map = new HashMap<String, Object>();
        map.put(ContextField.KEY_MERCHANT_ID, "00000001");
        map.put(ContextField.KEY_MATERIAL_TYPE, type);
        map.put(ContextField.KEY_PAGE_NO, pageNo);
        map.put(ContextField.KEY_PAGE_SIZE, pageSize);

        ProcessResult result = processService.execute(ProcessConstant.PROCESS_QUERY_MATERIAL, map);
        if (result.isSuccess()) {

            return newSuccessResult(result.getResultObject());
        } else {
            return newErrorResult(result.getCode());
        }

    }

    *//**
     * 更新素材的名称
     * @param request
     * @param materialId
     * @param materialName
     * @return
     *//*
    @RequestMapping(value = "/material/updateMaterial", method = RequestMethod.GET)
    @ResponseBody
    public String updateMaterialName(HttpServletRequest request, @RequestParam String materialId,
                                     @RequestParam String materialName,
                                     @RequestParam String newsList) {
        Merchant merchant = (Merchant) request.getSession().getAttribute(ContextField.KEY_MERCHANT);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put(ContextField.KEY_MERCHANT_ID, merchant.getMerchantId());
        map.put(ContextField.KEY_MATERIAL_ID, materialId);
        map.put(ContextField.KEY_MATERIAL_NAME, materialName);
        map.put(ContextField.KEY_NEWS_LIST,
            newsList.replaceAll(" ", "").replaceAll("[\\t\\n\\r]", ""));

        ProcessResult result = processService.execute(ProcessConstant.PROCESS_UPDATE_MATERIAL_NAME,
            map);
        if (result.isSuccess()) {
            return newSuccessResult(result.getResultObject());
        } else {
            return newErrorResult(result.getCode());
        }

    }

    *//**
     * 删除素材
     * @param request
     * @param materialId
     * @return
     *//*
    @RequestMapping(value = "/material/deleteMaterial", method = RequestMethod.GET)
    @ResponseBody
    public String deleteMaterial(HttpServletRequest request, @RequestParam String materialId) {
        Merchant merchant = (Merchant) request.getSession().getAttribute(ContextField.KEY_MERCHANT);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put(ContextField.KEY_MERCHANT_ID, merchant.getMerchantId());
        map.put(ContextField.KEY_MATERIAL_ID, materialId);

        ProcessResult result = processService.execute(ProcessConstant.PROCESS_DELETE_MATERIAL, map);
        if (result.isSuccess()) {
            return newSuccessResult(result.getResultObject());
        } else {
            return newErrorResult(result.getCode());
        }

    }

*/}
